.class public Lcom/glympse/android/glympseservice/FacebookWrapper;
.super Ljava/lang/Object;
.source "FacebookWrapper.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;,
        Lcom/glympse/android/glympseservice/FacebookWrapper$LoginDialogListener;,
        Lcom/glympse/android/glympseservice/FacebookWrapper$LogoutRequestListener;,
        Lcom/glympse/android/glympseservice/FacebookWrapper$RequestNameListener;
    }
.end annotation


# static fields
.field private static final APP_ID:Ljava/lang/String; = "175120038219"

.field private static final PERMISSIONS:[Ljava/lang/String;


# instance fields
.field private m_oFacebook:Lcom/facebook/android/Facebook;

.field private m_oFacebookStatusChange:Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;


# direct methods
.method static constructor <clinit>()V
    .locals 3

    .prologue
    .line 39
    const/4 v0, 0x2

    new-array v0, v0, [Ljava/lang/String;

    const/4 v1, 0x0

    .line 40
    const-string v2, "publish_stream"

    aput-object v2, v0, v1

    const/4 v1, 0x1

    .line 41
    const-string v2, "offline_access"

    aput-object v2, v0, v1

    .line 38
    sput-object v0, Lcom/glympse/android/glympseservice/FacebookWrapper;->PERMISSIONS:[Ljava/lang/String;

    .line 34
    return-void
.end method

.method public constructor <init>()V
    .locals 4

    .prologue
    const/4 v1, 0x0

    .line 48
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 44
    iput-object v1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    .line 45
    iput-object v1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebookStatusChange:Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;

    .line 50
    const-string v1, "FACEBOOK - Creating FacebookWrapper object"

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 54
    :try_start_0
    new-instance v1, Lcom/facebook/android/Facebook;

    const-string v2, "175120038219"

    invoke-direct {v1, v2}, Lcom/facebook/android/Facebook;-><init>(Ljava/lang/String;)V

    iput-object v1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    .line 57
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v1

    iget-object v1, v1, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-object v1, v1, Lcom/glympse/platform/Config;->m_strFacebookToken:Ljava/lang/String;

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v1

    if-nez v1, :cond_0

    .line 59
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v2, "Loading cached Facebook token: "

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-object v2, v2, Lcom/glympse/platform/Config;->m_strFacebookToken:Ljava/lang/String;

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, ", "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-wide v2, v2, Lcom/glympse/platform/Config;->m_lFacebookExpires:J

    invoke-virtual {v1, v2, v3}, Ljava/lang/StringBuilder;->append(J)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 61
    iget-object v1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-object v2, v2, Lcom/glympse/platform/Config;->m_strFacebookToken:Ljava/lang/String;

    invoke-virtual {v1, v2}, Lcom/facebook/android/Facebook;->setAccessToken(Ljava/lang/String;)V

    .line 62
    iget-object v1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-wide v2, v2, Lcom/glympse/platform/Config;->m_lFacebookExpires:J

    invoke-virtual {v1, v2, v3}, Lcom/facebook/android/Facebook;->setAccessExpires(J)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 69
    :cond_0
    :goto_0
    return-void

    .line 65
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 67
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method private RequestName()V
    .locals 4

    .prologue
    .line 319
    :try_start_0
    new-instance v0, Lcom/facebook/android/AsyncFacebookRunner;

    iget-object v2, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-direct {v0, v2}, Lcom/facebook/android/AsyncFacebookRunner;-><init>(Lcom/facebook/android/Facebook;)V

    .line 320
    .local v0, asyncRunner:Lcom/facebook/android/AsyncFacebookRunner;
    const-string v2, "me"

    new-instance v3, Lcom/glympse/android/glympseservice/FacebookWrapper$RequestNameListener;

    invoke-direct {v3, p0}, Lcom/glympse/android/glympseservice/FacebookWrapper$RequestNameListener;-><init>(Lcom/glympse/android/glympseservice/FacebookWrapper;)V

    invoke-virtual {v0, v2, v3}, Lcom/facebook/android/AsyncFacebookRunner;->request(Ljava/lang/String;Lcom/facebook/android/AsyncFacebookRunner$RequestListener;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 326
    .end local v0           #asyncRunner:Lcom/facebook/android/AsyncFacebookRunner;
    :goto_0
    return-void

    .line 322
    :catch_0
    move-exception v2

    move-object v1, v2

    .line 324
    .local v1, e:Ljava/lang/Exception;
    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method private StatusChanged()V
    .locals 2

    .prologue
    .line 398
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebookStatusChange:Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;

    if-eqz v0, :cond_0

    .line 401
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    new-instance v1, Lcom/glympse/android/glympseservice/FacebookWrapper$1;

    invoke-direct {v1, p0}, Lcom/glympse/android/glympseservice/FacebookWrapper$1;-><init>(Lcom/glympse/android/glympseservice/FacebookWrapper;)V

    invoke-virtual {v0, v1}, Lcom/glympse/platform/Platform;->PostToMainThreadIfNeeded(Lcom/glympse/platform/GRunnable;)Z

    .line 414
    :cond_0
    return-void
.end method

.method static synthetic access$0(Lcom/glympse/android/glympseservice/FacebookWrapper;)Lcom/facebook/android/Facebook;
    .locals 1
    .parameter

    .prologue
    .line 44
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    return-object v0
.end method

.method static synthetic access$1(Lcom/glympse/android/glympseservice/FacebookWrapper;)V
    .locals 0
    .parameter

    .prologue
    .line 315
    invoke-direct {p0}, Lcom/glympse/android/glympseservice/FacebookWrapper;->RequestName()V

    return-void
.end method

.method static synthetic access$2(Lcom/glympse/android/glympseservice/FacebookWrapper;)V
    .locals 0
    .parameter

    .prologue
    .line 395
    invoke-direct {p0}, Lcom/glympse/android/glympseservice/FacebookWrapper;->StatusChanged()V

    return-void
.end method

.method static synthetic access$3(Lcom/glympse/android/glympseservice/FacebookWrapper;)Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;
    .locals 1
    .parameter

    .prologue
    .line 45
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebookStatusChange:Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;

    return-object v0
.end method


# virtual methods
.method public IsSignedIn()Z
    .locals 1

    .prologue
    .line 98
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-virtual {v0}, Lcom/facebook/android/Facebook;->isSessionValid()Z

    move-result v0

    return v0
.end method

.method public PostToWall(Lcom/glympse/platform/GFacebook$Params;)Ljava/lang/String;
    .locals 9
    .parameter "oParams"

    .prologue
    const/4 v8, 0x0

    .line 331
    const/4 v5, 0x0

    .line 332
    .local v5, strResponse:Ljava/lang/String;
    const/4 v3, 0x0

    .line 333
    .local v3, strError:Ljava/lang/String;
    const/4 v1, 0x0

    .line 338
    .local v1, fSuccess:Z
    :try_start_0
    new-instance v2, Landroid/os/Bundle;

    invoke-direct {v2}, Landroid/os/Bundle;-><init>()V

    .line 339
    .local v2, oBundle:Landroid/os/Bundle;
    invoke-virtual {p1}, Lcom/glympse/platform/GFacebook$Params;->keySet()Ljava/util/Set;

    move-result-object v6

    invoke-interface {v6}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v7

    :goto_0
    invoke-interface {v7}, Ljava/util/Iterator;->hasNext()Z

    move-result v6

    if-nez v6, :cond_1

    .line 346
    const-string v6, "method"

    const-string v7, "stream.publish"

    invoke-virtual {v2, v6, v7}, Landroid/os/Bundle;->putString(Ljava/lang/String;Ljava/lang/String;)V

    .line 349
    iget-object v6, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-virtual {v6, v2}, Lcom/facebook/android/Facebook;->request(Landroid/os/Bundle;)Ljava/lang/String;

    move-result-object v5

    .line 350
    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "FACEBOOK: Post Response: "

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v6, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v6}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 355
    invoke-static {v5}, Lcom/facebook/android/Util;->parseJson(Ljava/lang/String;)Lorg/json/JSONObject;
    :try_end_0
    .catch Lcom/facebook/android/FacebookError; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    .line 386
    .end local v2           #oBundle:Landroid/os/Bundle;
    :goto_1
    if-nez v1, :cond_0

    invoke-static {v3}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v6

    if-eqz v6, :cond_0

    .line 388
    const-string v3, "Facebook responsed with an error while posting to your wall"

    .line 391
    :cond_0
    return-object v3

    .line 339
    .restart local v2       #oBundle:Landroid/os/Bundle;
    :cond_1
    :try_start_1
    invoke-interface {v7}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    .line 342
    .local v4, strKey:Ljava/lang/String;
    invoke-virtual {p1, v4}, Lcom/glympse/platform/GFacebook$Params;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v6

    check-cast v6, Ljava/lang/String;

    invoke-virtual {v2, v4, v6}, Landroid/os/Bundle;->putString(Ljava/lang/String;Ljava/lang/String;)V
    :try_end_1
    .catch Lcom/facebook/android/FacebookError; {:try_start_1 .. :try_end_1} :catch_0
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1

    goto :goto_0

    .line 359
    .end local v2           #oBundle:Landroid/os/Bundle;
    .end local v4           #strKey:Ljava/lang/String;
    :catch_0
    move-exception v6

    move-object v0, v6

    .line 361
    .local v0, e:Lcom/facebook/android/FacebookError;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .line 362
    invoke-virtual {v0}, Lcom/facebook/android/FacebookError;->getMessage()Ljava/lang/String;

    move-result-object v3

    goto :goto_1

    .line 367
    .end local v0           #e:Lcom/facebook/android/FacebookError;
    :catch_1
    move-exception v6

    move-object v0, v6

    .line 375
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v5}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v6

    if-nez v6, :cond_3

    const/16 v6, 0x22

    invoke-virtual {v5, v8}, Ljava/lang/String;->charAt(I)C

    move-result v7

    if-eq v6, v7, :cond_2

    invoke-virtual {v5, v8}, Ljava/lang/String;->charAt(I)C

    move-result v6

    invoke-static {v6}, Ljava/lang/Character;->isDigit(C)Z

    move-result v6

    if-eqz v6, :cond_3

    .line 377
    :cond_2
    const/4 v1, 0x1

    goto :goto_1

    .line 381
    :cond_3
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_1
.end method

.method public SetFacebookStatusChange(Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;)V
    .locals 0
    .parameter "oFacebookStatusChange"

    .prologue
    .line 92
    iput-object p1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebookStatusChange:Lcom/glympse/android/glympseservice/FacebookWrapper$FacebookStatusChange;

    .line 93
    return-void
.end method

.method public SetUpgradedSession(Ljava/lang/String;)V
    .locals 4
    .parameter "strSession"

    .prologue
    .line 75
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-virtual {v0, p1}, Lcom/facebook/android/Facebook;->setAccessToken(Ljava/lang/String;)V

    .line 76
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    const-wide/16 v1, 0x0

    invoke-virtual {v0, v1, v2}, Lcom/facebook/android/Facebook;->setAccessExpires(J)V

    .line 79
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v0

    iget-object v0, v0, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    iget-object v1, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-virtual {v1}, Lcom/facebook/android/Facebook;->getAccessToken()Ljava/lang/String;

    move-result-object v1

    iget-object v2, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-virtual {v2}, Lcom/facebook/android/Facebook;->getAccessExpires()J

    move-result-wide v2

    invoke-virtual {v0, v1, v2, v3}, Lcom/glympse/platform/Config;->SetFacebookToken(Ljava/lang/String;J)V

    .line 83
    invoke-direct {p0}, Lcom/glympse/android/glympseservice/FacebookWrapper;->RequestName()V

    .line 86
    invoke-direct {p0}, Lcom/glympse/android/glympseservice/FacebookWrapper;->StatusChanged()V

    .line 87
    return-void
.end method

.method public SignIn()V
    .locals 5

    .prologue
    .line 104
    const-string v0, "FACEBOOK - SignIn"

    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 105
    sget-object v0, Lcom/glympse/android/glympse/Glympse;->ms_oThis:Lcom/glympse/android/glympse/Glympse;

    if-eqz v0, :cond_0

    .line 107
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    sget-object v1, Lcom/glympse/android/glympse/Glympse;->ms_oThis:Lcom/glympse/android/glympse/Glympse;

    sget-object v2, Lcom/glympse/android/glympseservice/FacebookWrapper;->PERMISSIONS:[Ljava/lang/String;

    const/4 v3, 0x3

    new-instance v4, Lcom/glympse/android/glympseservice/FacebookWrapper$LoginDialogListener;

    invoke-direct {v4, p0}, Lcom/glympse/android/glympseservice/FacebookWrapper$LoginDialogListener;-><init>(Lcom/glympse/android/glympseservice/FacebookWrapper;)V

    invoke-virtual {v0, v1, v2, v3, v4}, Lcom/facebook/android/Facebook;->authorize(Landroid/app/Activity;[Ljava/lang/String;ILcom/facebook/android/Facebook$DialogListener;)V

    .line 109
    :cond_0
    return-void
.end method

.method public SignOut()V
    .locals 4

    .prologue
    .line 121
    const-string v2, "FACEBOOK - SignOut"

    invoke-static {v2}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 122
    invoke-static {}, Lcom/glympse/platform/Platform;->instance()Lcom/glympse/platform/Platform;

    move-result-object v2

    iget-object v2, v2, Lcom/glympse/platform/Platform;->m_oConfig:Lcom/glympse/platform/Config;

    invoke-virtual {v2}, Lcom/glympse/platform/Config;->ClearFacebookCredentials()V

    .line 124
    sget-object v2, Lcom/glympse/android/glympse/Glympse;->ms_oThis:Lcom/glympse/android/glympse/Glympse;

    if-eqz v2, :cond_0

    .line 128
    :try_start_0
    new-instance v0, Lcom/facebook/android/AsyncFacebookRunner;

    iget-object v2, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    invoke-direct {v0, v2}, Lcom/facebook/android/AsyncFacebookRunner;-><init>(Lcom/facebook/android/Facebook;)V

    .line 129
    .local v0, asyncRunner:Lcom/facebook/android/AsyncFacebookRunner;
    sget-object v2, Lcom/glympse/android/glympse/Glympse;->ms_oThis:Lcom/glympse/android/glympse/Glympse;

    new-instance v3, Lcom/glympse/android/glympseservice/FacebookWrapper$LogoutRequestListener;

    invoke-direct {v3, p0}, Lcom/glympse/android/glympseservice/FacebookWrapper$LogoutRequestListener;-><init>(Lcom/glympse/android/glympseservice/FacebookWrapper;)V

    invoke-virtual {v0, v2, v3}, Lcom/facebook/android/AsyncFacebookRunner;->logout(Landroid/content/Context;Lcom/facebook/android/AsyncFacebookRunner$RequestListener;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 136
    .end local v0           #asyncRunner:Lcom/facebook/android/AsyncFacebookRunner;
    :cond_0
    :goto_0
    return-void

    .line 131
    :catch_0
    move-exception v2

    move-object v1, v2

    .line 133
    .local v1, e:Ljava/lang/Exception;
    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0
.end method

.method public SingleSignInComplete(IILandroid/content/Intent;)V
    .locals 6
    .parameter "nRequestCode"
    .parameter "nResultCode"
    .parameter "oIntent"

    .prologue
    .line 114
    const-string v0, "FACEBOOK - SingleSignInComplete"

    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 115
    iget-object v0, p0, Lcom/glympse/android/glympseservice/FacebookWrapper;->m_oFacebook:Lcom/facebook/android/Facebook;

    const/4 v4, 0x3

    new-instance v5, Lcom/glympse/android/glympseservice/FacebookWrapper$LoginDialogListener;

    invoke-direct {v5, p0}, Lcom/glympse/android/glympseservice/FacebookWrapper$LoginDialogListener;-><init>(Lcom/glympse/android/glympseservice/FacebookWrapper;)V

    move v1, p1

    move v2, p2

    move-object v3, p3

    invoke-virtual/range {v0 .. v5}, Lcom/facebook/android/Facebook;->authorizeCallback(IILandroid/content/Intent;ILcom/facebook/android/Facebook$DialogListener;)V

    .line 116
    return-void
.end method
